#include "usr.h"
#include "mgmt_bk.h"
#include "usr_bk.h"
#include <stdio.h>
#include<string.h>


mgmt_bk_sqlist ml;
usr_sqlist ul;

void print_book_bid(char *bid){
	book *res;
	if(mgmt_bk_find(&ml,bid,&res))
		print_book(*res);
}
void print_usr_uid(unsigned  int *uid){
	print_by_uid(&ul,uid);
}

int main(){
	printf("welcome to book mgmt system\n");
	book b1;
	strcpy(b1.id,"1234567891");
	strcpy(b1.name,"gaozhiliangqianrushi");
	b1.price=4;
	book b2;
	strcpy(b2.id,"1234567892");
	strcpy(b2.name,"shujujiegou");
	b2.price=3;
	book b3;
	strcpy(b3.id,"1234567893");
	strcpy(b3.name,"linuxneihejiexi");
	b3.price=2;
	book b4;
	strcpy(b4.id,"1234567894");
	strcpy(b4.name,"hongloumeng");
	b4.price=1;
	book b5;
	strcpy(b5.id,"1234567895");
	strcpy(b5.name,"shuihuzhuan");
	b5.price=6;
	mgmt_bk_init(&ml);
	mgmt_bk_insert(&ml,b1);
	mgmt_bk_insert(&ml,b2);
	mgmt_bk_insert(&ml,b3);
	mgmt_bk_insert(&ml,b4);
	mgmt_bk_insert(&ml,b5);

	//mgmt_bk_traverse(&ml,cmp_by_null);
	mgmt_bk_traverse(&ml,cmp_by_price);
	//usr_init
	usr_init(&ul);
	usr u1;
	unsigned  int id1[10]={0,0,0,0,0,0,0,0,0,1};
	for(int i=0;i<10;i++)u1.id[i]=id1[i];
	strcpy(u1.name,"xiaoming");
	usr u2;
	unsigned  int id2[10]={0,0,0,0,0,0,0,0,0,2};
	for(int i=0;i<10;i++)u2.id[i]=id2[i];
	strcpy(u2.name,"xiaohong");
	usr u3;
	unsigned  int id3[10]={0,0,0,0,0,0,0,0,0,3};
	for(int i=0;i<10;i++)u3.id[i]=id3[i];
	strcpy(u3.name,"xiaolv");
	usr_insert(&ul,u1);
	usr_insert(&ul,u2);
	usr_insert(&ul,u3);
	usr_traverse(&ul);
	printf("***finished book and usr****\n");
	usr_bk_list ubl;
	usr_bk_init(&ubl);
	unsigned  int uf[10]={0,0,0,0,0,0,0,0,0,2};
	unsigned  int uf3[10]={0,0,0,0,0,0,0,0,0,3};
	printf("******start doing*****\n");
	jie(&ubl,uf,"1234567892");
	jie(&ubl,uf,"1234567893");
	jie(&ubl,uf,"1234567895");
	jie(&ubl,uf3,"1234567895");
	printf("******finished jie*****\n");
	find_by_uid(&ubl,uf);
	find_by_uid(&ubl,uf3);
	printf("******finished huan*****\n");
	huan(&ubl,uf,"1234567893");
	find_by_uid(&ubl,uf);

}

